package com.zjdiepu.www.proxy.biz.impl.own;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zjdiepu.www.base.core.BaseException;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.diepu.enums.TransferStatusDiepu;
import com.zjdiepu.www.proxy.biz.own.HzBiz;
import com.zjdiepu.www.proxy.biz.own.LogsBiz;
import com.zjdiepu.www.proxy.dao.own.HzDao;
import com.zjdiepu.www.proxy.dao.transfer.TransferLogsMapper;
import com.zjdiepu.www.proxy.dao.transfer.TransferLogsSubMapper;
import com.zjdiepu.www.proxy.model.dto.own.SysUserProxy;
import com.zjdiepu.www.proxy.model.dto.transfer.TransferLogs;
import com.zjdiepu.www.proxy.model.dto.transfer.TransferLogsSub;
@Service
public class LogsBizImpl implements LogsBiz{

	private int count = 0;
	
	@Autowired
	private HzDao hzDao;
	
	@Autowired
	private HzBiz hzBiz;
	
	@Autowired
	private TransferLogsMapper transferLogsMapper;
	
	@Autowired
	private TransferLogsSubMapper transferLogsSubMapper;
	
	@Override
	@Transactional(isolation=Isolation.READ_COMMITTED,readOnly=false,propagation=Propagation.REQUIRES_NEW,timeout=60)
	public void diepuLogs(SysUserProxy sysUserProxy,TransferLogs transferLogs, TransferLogsSub transferLogsSub) 
	{
		String userId = ResultFlagType.LOGIN_TIMEOUT.getCode().toString();
		String loginName = ResultFlagType.LOGIN_TIMEOUT.getValue();
		
		if(null != sysUserProxy)
		{
			userId = sysUserProxy.getUserId();
			loginName = sysUserProxy.getLoginName();
		}
		
		if(null == transferLogs)
		{
			hzBiz.loggerError("transferLogs is null");
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"transferLogs is null");
		}
		
		if(null == transferLogsSub)
		{
			transferLogsSub = new TransferLogsSub();
		}
		
		transferLogs.initInsertData(userId, loginName);
		transferLogs.setStatusEvent(Integer.valueOf(TransferStatusDiepu.STATUSEVENT0.getCode()));
		String transferLogsId = transferLogs.getId();
		count = transferLogsMapper.insert(transferLogs);
		if(count < 1)
		{
			hzBiz.loggerError("transferLogsMapper insert error");
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"transferLogsMapper insert error");
		}
		
		transferLogsSub.initInsertData(userId, loginName);
		transferLogsSub.setTransferLogsId(transferLogsId);
		transferLogsSub.setDataId(transferLogs.getDataId());
		transferLogsSub.setBankOrderNo(transferLogs.getBankOrderNo());
		transferLogsSub.setCmpSeq(transferLogs.getCmpSeq());
		transferLogsSub.setBusiId(transferLogs.getBusiId());
		transferLogsSub.setTransferModeId(transferLogs.getTransferModeId());
		transferLogsSub.setTransferModeName(transferLogs.getTransferModeName());
		count = transferLogsSubMapper.insert(transferLogsSub);
		if(count < 1)
		{
			hzBiz.loggerError("transferLogsSubMapper insert error");
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"transferLogsSubMapper insert error");
		}
		hzBiz.loggerInfo("{current module execution success} ... 当前模块执行成功");
	}

}
